import Mock from 'mockjs'


const data = Mock.mock({
	"userlist|10-100": [{
		'nickname': '@cname',
		'createAtTime': "@date",
		'desc': '@cword(10,20)',
		'id': '@id',
		'key': "@id"
	}]
})


Mock.mock('/api/user/list', () => {
	return {
		code: 200,
		data: data.userlist
	}
})


Mock.mock('/api/user/delete', 'post', (req) => {
	const { id } = JSON.parse(req.body)
	data.userlist = data.userlist.filter(v => v.id !== id)

	return {
		code: 200,
	}
})


Mock.mock('/api/user/add', 'post', (req) => {
	const user = JSON.parse(req.body)
	user.id = new Date().getTime()
	user.key = new Date().getTime()
	data.userlist.unshift(user)
	
	return {
		code: 200,
	}
})